package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Permission;
import cn.wolfcode.crm.page.PageResult;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IPermissionService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PermissionName;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@Controller
@RequestMapping("permission")
public class PermissionController {

    @Autowired
    private IPermissionService permissionService;

    @RequestMapping("")
    public String index() {
        //只负责跳转到permission.jsp页面即可
        return "permission";
    }
    @RequestMapping("list")
    @ResponseBody
    public PageResult list(QueryObject qo) {

        PageResult result = permissionService.query(qo);

        return result;
    }
    @RequestMapping("reload")
    @ResponseBody
    public JsonResult reload() {
        JsonResult result = new JsonResult();
        try{
            permissionService.reload();
         result.setMessage("加载成功");
        }catch (Exception e){
            e.printStackTrace();
            result.mark("加载失败");
        }
        return result;


    }

    @RequestMapping("listAll")
    @ResponseBody
    public PageResult listAll() {

        PageResult result = permissionService.listAll();

        return result;
    }
    @RequestMapping("queryByRoleId")
    @ResponseBody
    public PageResult queryByRoleId(Long roleId) {

        PageResult list = permissionService.queryByRoleId(roleId);
        return  list;
    }

}